package com.david.course_design.shopping_center.module.goods.goodsLunBoTuImageList.controller;

import com.david.course_design.shopping_center.module.goods.goodsLunBoTuImageList.entity.GoodsLunBoTuImageList;
import com.david.course_design.shopping_center.module.goods.goodsLunBoTuImageList.entity.vo.GoodsLunBoTuImageListVo;
import com.david.course_design.shopping_center.module.goods.goodsLunBoTuImageList.service.GoodsLunBoTuImageListService;
import com.david.course_design.shopping_center.result.ResultBody;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Controller
@ResponseBody
@Api(tags = "商品轮播图展示图片集合接口")
@RequestMapping("Goods/GoodsLunBoTuImageList/")
public class GoodsLunBoTuImageListController {
    // 依赖注入 dependency injection
    @Resource
    private GoodsLunBoTuImageListService goodsLunBoTuImageListService;

    @GetMapping("selectGoodsLunBoTuImageListByLunBoTuListId")
    @ApiOperation("通过轮播图集合id 查询轮播图图片集合")
    private ResultBody selectGoodsLunBoTuImageListByLunBoTuListId(Integer id) {

        List<GoodsLunBoTuImageList> goodsLunBoTuImageLists = goodsLunBoTuImageListService.selectGoodsLunBoTuImageListByLunBoTuListId(id);

        List<GoodsLunBoTuImageListVo> goodsLunBoTuImageListVos = new ArrayList<>();

        // 将数据处理成标准格式（将 GoodsLunBoTuImageList 对象 转换为 ==> GoodsLunBoTuImageListVo 对象）

        //  遍历 goodsLunBoTuImageLists 集合
        for (int i = 0; i < goodsLunBoTuImageLists.size(); i++) {

            //  取出 goodsLunBoTuImageLists 集合中的每一个元素
            GoodsLunBoTuImageList goodsLunBoTuImageList = goodsLunBoTuImageLists.get(i);

            //  创建 goodsLunBoTuImageListVo 对象 将 goodsLunBoTuImageList 中的 id 和 imgUrl 传入
            GoodsLunBoTuImageListVo goodsLunBoTuImageListVo = new GoodsLunBoTuImageListVo(goodsLunBoTuImageList.getId(), goodsLunBoTuImageList.getImgUrl());

            //  将创建的 goodsLunBoTuImageListVo 对象添加到 goodsLunBoTuImageListVos 集合中
            goodsLunBoTuImageListVos.add(goodsLunBoTuImageListVo);

        }

        //  判断 goodsLunBoTuImageListVos 集合是否为空
        if (goodsLunBoTuImageListVos != null || goodsLunBoTuImageListVos.size() != 0) {

            //  如果不为空 将处理好的数据返回
            return ResultBody.success(goodsLunBoTuImageListVos);

        } else {

            //  如果为空，提示 ==> "没有找到数据！"
            return ResultBody.error("", "没有找到数据!");

        }

    }

}
